package javaBase.nowcoder.HJ45_A_名字的漂亮度;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Integer num = Integer.parseInt(br.readLine());

        int i = 0;
        int sum = 0;
        while (i < num) {
            String str = br.readLine();
            HashMap<Character, Integer> map = new HashMap<>();
            for (int j = 0; j < str.length(); j++) {
                char c = str.charAt(j);
                map.merge(c, 1, Integer::sum);
            }
            List<Map.Entry<Character, Integer>> collect = map.entrySet().stream().sorted((o1, o2) -> {
                return o2.getValue() - o1.getValue();
            }).collect(Collectors.toList());
            for (int j = 0; j < collect.size(); j++) {
                int i1 = collect.get(j).getValue() * (26 - j > 0 ? 26 - j : 1);
                sum += i1;
            }
            i++;
            System.out.println(sum);
            sum = 0;
        }


    }
}